package com.dayang.redbook.note.biz.rpc;

import com.dayang.framework.common.domain.response.Response;
import com.dayang.redbook.user.api.UserFeignApi;
import com.dayang.redbook.user.dto.req.FindUserByIdReqDTO;
import com.dayang.redbook.user.dto.resp.FindUserByIdRspDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author: dayang
 * @since: 2024/8/27
 * @description: 用户服务
 */
@Component
public class UserRpcService {
    @Resource
    private UserFeignApi userFeignApi;

    /**
     * 查询用户信息
     * @param userId 用户id
     * @return 用户信息
     */
    public FindUserByIdRspDTO findById(Long userId) {
        FindUserByIdReqDTO findUserByIdReqDTO = new FindUserByIdReqDTO();
        findUserByIdReqDTO.setId(userId);
        Response<FindUserByIdRspDTO> response = userFeignApi.findById(findUserByIdReqDTO);
        if (Objects.isNull(response) || !response.isSuccess()) {
            return null;
        }
        return response.getData();
    }

}
